#include <jsi/jsi.h>

#include "utils/Logger.h"

namespace test_host_obj {
using Value = facebook::jsi::Value;
using Runtime = facebook::jsi::Runtime;
using PropNameID = facebook::jsi::PropNameID;
using String = facebook::jsi::String;

class TestHostObject : public facebook::jsi::HostObject {
  Value get(Runtime& rt, const PropNameID& name) override {
    if (name.utf8(rt) == "x") {
      return x;
    }
    if (name.utf8(rt) == "y") {
      return String::createFromUtf8(rt, y);
    }
    return String::createFromUtf8(rt, "TestHostObject::" + name.utf8(rt));
  }
  void set(Runtime& rt, const PropNameID& name, const Value& value) override {
    if (name.utf8(rt) == "x") {
      x = value.getNumber();
    } else if (name.utf8(rt) == "y") {
      y = value.getString(rt).utf8(rt);
    }
    logInfo("done set in TestHostObject\n");
  }

  std::vector<PropNameID> getPropertyNames(Runtime& rt) override {
    std::vector<PropNameID> res;
    res.push_back(PropNameID::forUtf8(rt, "x"));
    res.push_back(PropNameID::forUtf8(rt, "y"));
    return res;
  }

 private:
  int x;
  std::string y;
};
}  // namespace test_host_obj
